package com.lanou3g.dllo.baidumusic.musiclibrary.radio;

import android.content.Intent;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.lanou3g.dllo.baidumusic.R;
import com.lanou3g.dllo.baidumusic.base.BaseFragment;
import com.lanou3g.dllo.baidumusic.musiclibrary.radio.radiodetail.EachRadioDetailActivity;
import com.lanou3g.dllo.baidumusic.tools.MyRvOnClickListener;
import com.lanou3g.dllo.baidumusic.tools.MyVolley;

/**
 * Created by dllo on 16/6/25.
 */
public class RadioDetailFragment extends BaseFragment {
    private RadioDetailBean radioDetailBean;
    private RadioDetailAdapter radioDetailAdapter;
    private RecyclerView radioDetailRecyclerView;

    @Override
    public int setLayout() {
        return R.layout.fragment_radiodetail;
    }

    @Override
    public void initView(View view) {
        radioDetailRecyclerView = (RecyclerView) view.findViewById(R.id.radiodetail_recyclerview);
    }

    @Override
    public void initData() {

        radioDetailAdapter = new RadioDetailAdapter();
        int id = getArguments().getInt("id");
        String url = "http://tingapi.ting.baidu.com/v1/restserver/ting/?method=baidu.ting.scene.getCategoryScene&category_id=" + id + "&version=5.2.5&from=ios&channel=appstore";
        MyVolley.getMyVolley().initGson(url, new MyVolley.GetGsonListener<RadioDetailBean>() {
            @Override
            public void getGsonListener(RadioDetailBean data) {
                radioDetailBean = data;
                radioDetailAdapter.setRadioDetailBean(data);
                radioDetailRecyclerView.setAdapter(radioDetailAdapter);
                radioDetailRecyclerView.setLayoutManager(new GridLayoutManager(context, 3));

            }
        }, RadioDetailBean.class);

        radioDetailAdapter.setMyRvOnClickListener(new MyRvOnClickListener() {
            @Override
            public void onClick(int position) {
                String sceneId = radioDetailBean.getResult().get(position).getScene_id();
                Intent intent = new Intent(context, EachRadioDetailActivity.class);
                intent.putExtra("sceneId",sceneId);
                intent.putExtra("sceneName",radioDetailBean.getResult().get(position).getScene_name());
                startActivity(intent);
                getActivity().finish();
            }
        });

    }
}
